package com.culturalCenter.dataCenter.service.impl.training;

import com.culturalCenter.dataCenter.customEntity.responseParam.training.TrainingPromotionAnalysisResponse;
import com.culturalCenter.dataCenter.entity.training.TrainingApply;
import com.culturalCenter.dataCenter.entity.training.TrainingClientCount;
import com.culturalCenter.dataCenter.entity.training.TrainingInfoCount;
import com.culturalCenter.dataCenter.mapper.training.TrainingApplyMapper;
import com.culturalCenter.dataCenter.mapper.training.TrainingClientCountMapper;
import com.culturalCenter.dataCenter.mapper.training.TrainingInfoCountMapper;
import com.culturalCenter.dataCenter.service.training.TrainingPromotionAnalysisService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author colors
 * @date 2021/2/5 11:18
 */
@Service
public class TrainingPromotionAnalysisServiceImpl implements TrainingPromotionAnalysisService {

    @Resource
    private TrainingInfoCountMapper trainingInfoCountMapper;
    @Resource
    private TrainingApplyMapper trainingApplyMapper;
    @Resource
    private TrainingClientCountMapper trainingClientCountMapper;

    @Override
    public TrainingPromotionAnalysisResponse getPromotionAnalysis(String trainingId) {
        TrainingPromotionAnalysisResponse trainingPromotionAnalysisResponse = new TrainingPromotionAnalysisResponse();
        // 培训点击统计
        List<TrainingInfoCount> browseList = trainingInfoCountMapper.selectSignUpRate(trainingId);
        if (CollectionUtils.isNotEmpty(browseList)) {
            trainingPromotionAnalysisResponse.setBrowseList(browseList);
        }
        // 报名平台统计
        List<TrainingClientCount> signUpPlatformList = trainingClientCountMapper.selectSignUpPlatform(trainingId);
        if (CollectionUtils.isNotEmpty(signUpPlatformList)) {
            trainingPromotionAnalysisResponse.setSignUpPlatformList(signUpPlatformList);
        }
        // 报名时段统计
        List<TrainingApply> signUpTimeList = trainingApplyMapper.selectSignUpTime(trainingId);
        if (CollectionUtils.isNotEmpty(signUpTimeList)) {
            int sum = signUpTimeList.stream().mapToInt(TrainingApply::getSignUpNum).sum();
            for (TrainingApply trainingApply : signUpTimeList) {
                trainingApply.setTotalNum(sum);
            }
            trainingPromotionAnalysisResponse.setSignUpTimeList(signUpTimeList);
        }
        return trainingPromotionAnalysisResponse;
    }

}
